function process_inline_macro_extension(obj) {

    var attrs = obj["attrs"];
    var parent = obj["parent"];
    var __self = obj["__self"];
    var nil = obj["nil"];
    var name = obj["name"];
    var target = obj["target"];

    var title = (attrs['$[]']("title")),
        alt = (attrs['$[]']("alt")),
        caption = (attrs['$[]']("caption")),
        width = (attrs['$[]']("width")),
        height = (attrs['$[]']("height")),
        scale = (attrs['$[]']("scale")),
        align = (attrs['$[]']("align")),
        type = (attrs['$[]']("type")),
        cache = (attrs['$[]']("cache")),
        role = (attrs['$[]']("role")),
        link = (attrs['$[]']("link")),
        float = (attrs['$[]']("float")),
        imagesdir = parent.$document().$attr('imagesdir', '');

    var filename = "";

    //if (!attrs['$[]']("file")["$nil?"]()) {
    //    var extension = attrs['$[]']("extension")["$nil?"]() ? "" : "." + attrs['$[]']("extension");
    //    filename = "" + attrs['$[]']("file") + extension;
    //}

    var parts = target.split(",");


    if (parts.length > 1) {
        var extension = parts.length > 2 ? "." + parts[2] : "";
        filename = "" + parts[1] + extension;
    }

    var content = "" + parts[0];
    var command = name;

    if (filename != "") {
        target = parent.$image_uri(filename);
    }
    else {
        target = parent._cached_image_uri(content);
        var host = ((typeof location) != "undefined") ? "http://" + location.host : "";
        filename = host + target;
    }

    var stems = ["stem", "asciimath", "latexmath", "mathml"];
    if (stems.indexOf(name) != -1) {
        content = parseStems(parent, content, name);
        command = "math";
    }

    var parameters = [content, type, imagesdir, target, name].map(function (e) {
        return e + "";
    });

    //afx[command].apply(afx,parameters);

    postMessage(JSON.stringify({
        type: "afx",
        func: command,
        parameters: parameters
    }));

    var attributes = {
        "target": filename,
        "title": title,
        "alt": alt,
        "caption": caption,
        "width": width,
        "height": height,
        "scale": scale,
        "align": align,
        "role": role,
        "link": link,
        "float": float
    };

    var keys = Object.keys(attributes);

    keys.forEach(function (key) {
        if (attributes[key]["$nil?"]()) {
            delete attributes[key];
        }
    });

    return __self.$create_inline(parent, "image", nil, Opal.hash(attributes)).$convert();
    //return __self.$create_image_block(parent, Opal.hash(attributes));
}

function registerInlineMacroExtensions(name) {
    /* Generated by Opal 0.9.2 */
    Opal.modules[name + "-inline-macro/extension"] = function (Opal) {
        Opal.dynamic_require_severity = "ignore";
        var OPAL_CONFIG = {method_missing: true, arity_check: false, freezing: true, tainting: true};
        var self = Opal.top, $scope = Opal, nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice, $klass = Opal.klass, $hash2 = Opal.hash2;

        Opal.add_stubs(['$==', '$include', '$use_dsl', '$named', '$name_positional_attributes', '$document', '$convert', '$new']);
        if ($scope.get('RUBY_ENGINE')['$==']("opal")) {
        }
        ;
        self.$include(Opal.get('Asciidoctor'));
        return (function ($base, $super) {
            function $ExtensionInlineMacro() {
            };
            var self = $ExtensionInlineMacro = $klass($base, $super, name + 'InlineMacro', $ExtensionInlineMacro);

            var def = self.$$proto, $scope = self.$$scope;

            self.$use_dsl();
            self.$named(name);
            self.$using_format("short");
            self.$name_positional_attributes("target", "file", "extension");

            return (Opal.defn(self, '$process', function (parent, target, attributes) {
                    var __self = this, doc = nil;

                    return process_inline_macro_extension({
                        parent: parent,
                        attrs: attributes,
                        __self: __self,
                        nil: nil,
                        name: name,
                        target: target
                    });


                    //return $scope.get('Inline').$new(parent, "image", nil, Opal.hash2([], {})).$convert();
                    //return self.$create_inline(parent, "image", nil, Opal.hash({target: "deneme.png"})).$convert();
                }), nil) && 'process';
        })($scope.base, (($scope.get('Extensions')).$$scope.get('InlineMacroProcessor')));
    };

    /* Generated by Opal 0.9.2 */
    (function (Opal) {
        Opal.dynamic_require_severity = "ignore";
        var OPAL_CONFIG = {method_missing: true, arity_check: false, freezing: true, tainting: true};
        var $a, $b, TMP_1, self = Opal.top, $scope = Opal, nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice;

        Opal.add_stubs(['$==', '$require', '$register', '$inline_macro']);
        if ($scope.get('RUBY_ENGINE')['$==']("opal")) {
            self.$require(name + "-inline-macro/extension")
        }
        ;
        return ($a = ($b = (($scope.get('Asciidoctor')).$$scope.get('Extensions'))).$register, $a.$$p = (TMP_1 = function () {
            var self = TMP_1.$$s || this;

            return self.$inline_macro($scope.get(name + 'InlineMacro'))
        }, TMP_1.$$s = self, TMP_1), $a).call($b);
    })(Opal);
}

// there is a bug for math asciimath:[] generates text + image ascii<img>
["stem", "asciimath", "latexmath", "mathml"].forEach(function (name) {
    registerInlineMacroExtensions(name);
});
